SHELL = /bin/sh

host_alias = i386
host_triplet = i386-pc-none
CC = arm-linux-gcc
#CC = /usr/local/bvd-2.2.5/bin/arm-linux-gcc
LN_S = ln -s
OBJCOPY = arm-linux-objcopy
#OBJCOPY = /usr/local/bvd-2.2.5/bin/arm-linux-objcopy
OCFLAGS = -O binary -R .note -R .comment -S
PACKAGE = blob_bl

# WARNING: start.S *must* be the first file, otherwise the target will
# be linked in the wrong order!
blob_bl_elf32_SOURCES =  start.S command.c serial.c time.c util.c irq.c xmodem.c ymodem.c mem.c crc16.c doc_op.c
blob_bl_elf32_SOURCES+=pcf50606.c gpio.c udelay.c
blob_bl_elf32_SOURCES+=memcpy.c memset.c memcmp.c strlen.c strncmp.c printf.c main.c
blob_bl_elf32_SOURCES+=bvd_usb_ctl.c bvd_usb_ep0.c bvd_usb_ep1.c bvd_usb_ep2.c usb_serial_download.c serial-bvdusb.c
blob_bl_elf32_SOURCES+=elrudc.c elruser.c XYMUtils.c XYmdm.c xsf.c
blob_bl_elf32_SOURCES+=md5lib.c KeypadTest.c bcm2121.c buart.c ftuart.c gsm.c

blob_bl_elf32_LDFLAGS =  	-Wl,-T,./ld-script

blob_bl_elf32_LDADD = "./../build tools/libgcc.a"

# GCC 3.2.1 + Kernel 2.4.19
#INCLUDES =  -I.	-I../include -I/usr/local/arm-linux/arm-linux/include -I/usr/local/arm-linux/lib/gcc-lib/arm-linux/3.2.1/include -I/usr/local/arm-linux/arm-linux/sys-include -I../../kernel/include -I/root/work/N2/kernel/linux-2.4.21
# GCC 3.3.2 + Kernel 2.4.21
INCLUDES =  -I. -I../include -I./mdoc
#-I../../kernel/include -I/usr/local/arm-linux/arm-linux/include -I/usr/local/arm-linux/lib/gcc-lib/arm-linux/3.2.1/include -I./mdoc

DEFS =
CPPFLAGS =
LDFLAGS = -static -nostdlib
LIBS =
blob_bl_elf32_OBJECTS =  start.o command.o serial.o time.o util.o irq.o xmodem.o ymodem.o mem.o crc16.o doc_op.o
blob_bl_elf32_OBJECTS+=pcf50606.o gpio.o udelay.o
blob_bl_elf32_OBJECTS+=memcpy.o memset.o memcmp.o strlen.o strncmp.o printf.o main.o
blob_bl_elf32_OBJECTS+=bvd_usb_ctl.o bvd_usb_ep0.o bvd_usb_ep1.o bvd_usb_ep2.o usb_serial_download.o serial-bvdusb.o
blob_bl_elf32_OBJECTS+=elrudc.o elruser.o XYMUtils.o XYmdm.o xsf.o
blob_bl_elf32_OBJECTS+=md5lib.o KeypadTest.o bcm2121.o buart.o ftuart.o gsm.o
blob_bl_elf32_OBJECTS+= ./mdoc/tffs.o
FLASH=n
ifeq ($(FLASH),y)
blob_bl_elf32_OBJECTS+= flash.o
endif

blob_bl_elf32_DEPENDENCIES =
blob_bl_OBJECTS =
blob_bl_LDADD = $(LDADD)

CFLAGS =  -O2 $(INCLUDES) -Wall -g -nostdinc -mcpu=xscale -mtune=xscale -fomit-frame-pointer -fPIC
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@

SOURCES = $(blob_bl_elf32_SOURCES) $(blob_bl_SOURCES)
OBJECTS = $(blob_bl_elf32_OBJECTS) $(blob_bl_OBJECTS)

all: blob_bl System.map

.c.o:
	$(COMPILE) -c $<

.S.o:
	$(COMPILE) -D__ASSEMBLY__ -c -g $<


blob_bl-elf32: $(blob_bl_elf32_OBJECTS) $(blob_bl_elf32_DEPENDENCIES)
	$(LINK) $(blob_bl_elf32_LDFLAGS) $(blob_bl_elf32_OBJECTS) $(blob_bl_elf32_LDADD) $(LIBS)
version.o:
	gcc -o version version.c

version_touch:	version.o
	./version > ./version.h

start.o: start.S ../include/config.h
command.o: command.c ../include/config.h
flash.o: flash.c ../include/config.h
main.o: main.c ../include/config.h
serial.o: serial.c ../include/config.h
time.o: time.c ../include/config.h
util.o: util.c ../include/config.h
irq.o : irq.c ../include/config.h
ymodem.o : ymodem.c ../include/config.h
xmodem.o : xmodem.c ../include/config.h

./mdoc/tffs.o:
	make -C mdoc
	copy .\mdoc\tffs.o .\

blob_bl : blob_bl-elf32
	$(OBJCOPY) $(OCFLAGS) $< $@

System.map : blob_bl-elf32


clean :
	-del *.o blob_bl blob_bl-elf32
	-del .\mdoc\*.o
